#include "settings.h"

#include <stdexcept>

#include "details/xml.h"

#ifdef HAVE_DMALLOC_H
#include <dmalloc.h>
#endif

namespace fastcgi
{

XmlUtils::XmlUtils() {
}

XmlUtils::~XmlUtils() {
}

void
XmlUtils::throwUnless(bool value) {
	if (!value) {
		const char *message = "unknown xml error";
		std::runtime_error exc(message);
		throw exc;
	}
}

const char*
XmlUtils::value(xmlNodePtr node) {
	assert(node);
	xmlNodePtr child = node->FirstChild();
	if (child && child->TEXT) {
		return (const char*) child->TEXT;
	}
	return NULL;
}

const char*
XmlUtils::attrValue(xmlNodePtr node, const char *name) {
	assert(node);
	return node->ToElement()->Attribute(name);
}

const xmlDocPtr
XmlUtils::xmlParseFile(char * file){
   xmlDocPtr doc = new TiXmlDocument(file);
   doc->LoadFile();
   return doc;
}

const xmlNodePtr
XmlUtils::xmlDocGetRootElement(xmlDocPtr node){
    return node->RootElement();
}

void
XmlDocCleaner::clean(xmlDocPtr doc) {
	delete doc;
}

void
XmlNodeCleaner::clean(xmlNodePtr node){

}
} // namespace fastcgi
